package dao;

import java.util.ArrayList;
import java.util.List;

import pojo.Sanpham;
import pojo.Sanphamdoanhthu;

public class SanphamdoanhthuDAO {
	
	public static List<Sanphamdoanhthu> ConvertToListSanPhamDoanhThu(List<Object[]> source)
	{		
		List<Sanphamdoanhthu> lstSPDT = new ArrayList<Sanphamdoanhthu>();
		
		Sanphamdoanhthu spdt = null;
		List<Sanpham> lstSanpham = (new ChitiethoadonDAO()).GetDanhSachSanPham();
		List<Integer> lstMaSanPham = GetMaSanPhamFromList(lstSanpham);
		for (int i = 0; i< source.size(); i++)
		{
			spdt = new Sanphamdoanhthu();
			spdt.setSanpham(lstSanpham.get(lstMaSanPham.indexOf((int)source.get(i)[0])));
			spdt.setSoluong((long)source.get(i)[1]);
			spdt.setTongtien((long)source.get(i)[2]);
			lstSPDT.add(spdt);
		}
		
		return lstSPDT;
	}
	
	private static List<Integer> GetMaSanPhamFromList(List<Sanpham> lstSanpham)
	{
		List<Integer> result = new ArrayList<Integer>();
		for (int i = 0; i< lstSanpham.size(); i++)
		{
			result.add(lstSanpham.get(i).getMasanpham());
		}
		return result;
	}
}
